<?php

use yii\grid\GridView;
use common\helpers\Url;
use common\enums\GenderEnum;
use common\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\daterange\DateRangePicker;

$this->title                   = '订单管理';
$this->params['breadcrumbs'][] = $this->title;
$addon                         = <<< HTML
<span class="input-group-addon">
    <i class="glyphicon glyphicon-calendar"></i>
</span>
HTML;
?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">


            <div class="box-header">
                <h3 class="box-title"><?= $this->title; ?></h3>
                <div class="box-tools">
                    <?= Html::a('Excel 导出订单', ['excel'], ['class' => "btn btn-primary btn-xs"]); ?>
                </div>

            </div>
            <div class="col-sm-12" style="margin-top: 10px;">
                <?php $form = ActiveForm::begin([
                    'action' => Url::to(['index']),
                    'method' => 'get',
                ]); ?>
                <div class="col-sm-3">
                    <div class="input-group drp-container">
                        <?= DateRangePicker::widget([
                            'name'              => 'queryDate',
                            //'value'             => $start_time . '-' . $end_time,
                            'readonly'          => 'readonly',
                            'useWithAddon'      => TRUE,
                            'convertFormat'     => TRUE,
                            'startAttribute'    => 'start_time',
                            'endAttribute'      => 'end_time',
                            //'startInputOptions' => ['value' => $start_time],
                            //'endInputOptions'   => ['value' => $end_time],
                            'pluginOptions'     => [
                                'locale' => ['format' => 'Y-m-d H:i:s'],
                            ],
                        ]) . $addon; ?>
                    </div>
                </div>
<!--                <div class="col-sm-2">-->
<!--                        --><?//= Html::dropDownList('type', NULL, [
//                            'open_time'  => '开仓时间',
//                            'close_time' => '平仓时间',
//                        ], [
//                            'options' => [$type => ['selected' => TRUE]],
//                            'class'   => 'form-control',
//                        ]) ?>
<!--                </div>-->
                <?php if(empty($daili_type)){?>
                <div class="col-sm-2">
                    <?= Html::dropDownList('agentid', NULL, $agentlist, [
                        'options' => [$agentid => ['selected' => TRUE]],
                        'prompt'  => '请选择代理商',
                        'class'   => 'form-control',
                    ]) ?>
                </div>
                <?php }?>
                <div class="col-sm-2">
                    <?= Html::textInput('username', '', [
                        'class'       => 'form-control',
                        'id'          => 'test-input',
                        'placeholder' => '请输入要查询的用户名',
                    ]) ?>
                </div>

                <div class="col-sm-2">
                    <div class="input-group">

                        <?= Html::dropDownList('close_type', NULL, [
                            '平仓'  => '平仓',
                            '持仓'  => '持仓',
                            '自动平仓'  => '自动平仓',
                            '手动平仓' => '手动平仓',
                            '强制平仓' => '强制平仓',
                        ], [
                            'options' => [$close_type => ['selected' => TRUE]],
                            'prompt'  => '请选择类型',
                            'class'   => 'form-control',
                        ]) ?>


                        <span class="input-group-btn"><button class="btn btn-white"><i
                                        class="fa fa-search"></i> 搜索</button></span>
                    </div>
                </div>
                <?php ActiveForm::end(); ?>
            </div>

            <!-- /.box-header -->
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel'  => $searchModel,
                    //重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'columns'      => [
                        [
                            'class'   => 'yii\grid\SerialColumn',
                            'visible' => FALSE, // 不显示#
                        ],
                        [
                            'attribute' => 'username',
                            'filter'    => FALSE, //不显示搜索框
                            'label'     => '用户名',
                            'value'     => 'member_info.username',
                        ],
                        [
                            'attribute' => 'symbol_cn',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->symbol_cn;
                            },
                        ],
                        [
                            'attribute' => 'contract_size',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->contract_size;
                            },
                        ],
                        [
                            'attribute' => 'open_time',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->open_time;
                            },
                        ],
                        [
                            'attribute' => 'open_price',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->open_price;
                            },
                        ],
                        [
                            'attribute' => 'close_time',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->close_time;      
                            },
                        ],
                        [
                            'attribute' => 'close_price',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->close_price;
                            },
                        ],
                        [
                            'attribute' => 'service_fee',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->service_fee;
                            },
                        ],
                        [
                            'attribute' => 'deposit',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->deposit;
                            },
                        ],
                        [
                            'attribute' => 'profit',
                            'filter'    => FALSE, //不显示搜索框
                            'value'     => function ($model) {
                                return $model->profit;
                            },
                        ],
                        [
                            'attribute' => 'overfee',
                            'filter'    => FALSE, //不显示搜索框
                        ],
                        //                        [
                        //                            'attribute' => 'state',
                        //                            'value'     => function ($model) {
                        //                                return $model->state;
                        //                            },
                        //                            'filter'    => Html::activeDropDownList($searchModel, 'state',
                        //                                GenderEnum::$listState, [
                        //                                    'prompt' => '全部',
                        //                                    'class'  => 'form-control',
                        //                                ]),
                        //                        ],
                        [
                            'attribute' => 'close_type',
                            'value'     => function ($model) {
                                return $model->close_type ?? '';
                            },
                            'filter'    => false
                        ],
                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template'=> '{edit}',
                            'buttons' => [
                                'edit' => function ($url, $model, $key) {
                                    if($model->state=='持仓'){
                                        return Html::linkButton(['ajax-edit','id' => $model->id], '平仓');
                                    }
                                },
                            ],
                        ],
                    ],
                ]); ?>
                <p><span style="color: blue">总开仓金额：<?= $order->open_price?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span style="color: blue">总手续费：<?= $order->service_fee?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span style="color: blue">订单保证金：<?= $order->deposit?></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <span style="color: blue">订单总盈亏损：<?= $order->profit?></span>
                </p>
            </div>
        </div>
    </div>
</div>





